package cn.edu.njust.service.impl;

import cn.edu.njust.mapper.ResultMapper;
import cn.edu.njust.mapper.UserMapper;
import cn.edu.njust.pojo.Result;
import cn.edu.njust.service.ResultService;
import cn.edu.njust.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class ResultServiceImpl implements ResultService {

    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public List<Result> selectAllResult() {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        ResultMapper mapper = sqlSession.getMapper(ResultMapper.class);

        List<Result> results = mapper.selectAllResult();

        sqlSession.close();

        return results;
    }

    @Override
    public void add(Result result) {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        ResultMapper mapper = sqlSession.getMapper(ResultMapper.class);

        mapper.add(result);

        sqlSession.commit();

        sqlSession.close();

    }
}
